import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_example/get_connect/model/my_get_connect_model.dart';
import 'package:getx_example/get_connect_statemixin/controller/my_get_connect_statemixin_controller.dart';

class MyGetConnectStateMixinPage extends GetView<MyGetConnectStateMixinController> {
  static const String route = "/MyGetConnectStateMixinPage";

  const MyGetConnectStateMixinPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('GetConnectStateMixin'),
        ),
        body: 
        controller.obx(
          (state) {
            return ListView.separated(
              itemCount: state!.length,
              itemBuilder: (context, index) {
                final MyGetConnectModel getConnectModel = state[index];
                return ListTile(
                  onTap: () {},
                  title: Text(getConnectModel.title),
                  trailing: Text("\$${getConnectModel.body}"),
                );
              },
              separatorBuilder: (BuildContext context, int index) {
                return const Divider();
              },
            );
          },
          onError: (error) {
            return Center(
              child: Text(error.toString()),
            );
          },
          onLoading: const SizedBox(
            width: double.infinity,
            height: double.infinity,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                CircularProgressIndicator(),
                SizedBox(height: 10),
                Text(
                  "疯狂加载中...",
                  style: TextStyle(color: Colors.blue, fontSize: 16),
                ),
              ],
            ),
          ),
          onEmpty: const Center(
            child: Text("没有数据"),
          ),
        ));
  }
}
